using OnePiece.Ui.Controls.UI;
using OnePiece.Core.Extension;

namespace OnePiece.Ui.Controls
{
    using System.IO;
    using System.Web.Mvc;


    /// <summary>
    /// Displays a message box in an ASP.NET MVC view.
    /// </summary>
    public class GridNavigator : jQueryViewComponentBase
    {


        /// <summary>
        /// Initializes a new instance of the <see cref="GridNavigator"/> class.
        /// </summary>
        /// <param name="viewContext">The view context.</param>
        /// <param name="clientSideObjectWriterFactory">The client side object writer factory.</param>
        public GridNavigator(ViewContext viewContext, IClientSideObjectWriterFactory clientSideObjectWriterFactory) : base(viewContext, clientSideObjectWriterFactory)
        {
            //set the grid css and js
            //this.ScriptFileNames.Add("/jqueryplugin/jquery.jqGridNavigator-3.5.3/js/jquery.jqGridNavigator.min.js");

            //listener for the event
            
            
            //default of properties
            ShowAdd = true;
            ShowDelete = true;
            ShowEdit = true;
            ShowRefresh = true;
            ShowSearch = true;
            ShowViewDetail = false;
            //CloseOnEscape = true;
            IsMultipleSearch = true;
        }

           
        public bool ShowAdd { get; set; }
        public bool ShowDelete { get; set; }        
        public bool ShowEdit { get; set; }
        public bool ShowRefresh { get; set; }
        public bool ShowSearch { get; set; }        
        public bool ShowViewDetail { get; set; }

        //public bool CloseOnEscape { get; set; }
        public bool IsMultipleSearch { get; set; }

      

        

        public override void WriteInitializationScript(TextWriter writer)
        {
            IClientSideObjectWriter objectWriter = ClientSideObjectWriterFactory.Create(Id, "navGrid", writer);

            objectWriter.Start() 
                        .AppendText("'#{0}_pager'".FormatWith(this.Name))       
                        .Append("add", ShowAdd, true)
                        .Append("del", ShowDelete, true)
                        .Append("edit", ShowEdit, true)
                        .Append("refresh", ShowRefresh, true)
                        .Append("search", ShowSearch, true)
                        .Append("view", ShowViewDetail, false)
                        .End()
                        .AppendText(",{}") //edit options
                        .AppendText(",{}") //add options
                        .AppendText(",{}") //del options
                        .Append("multipleSearch", IsMultipleSearch)
                        //.Append("closeOnEscape", CloseOnEscape)                         
                        .Complete();

            base.WriteInitializationScript(writer);
        }


      
    }
}